<template>
	<view class="contont">
		<nav-bar :title="title" :iconLeft="true" />
		<view class="content-bgc">
			<view class="b-con">
				<view style="margin-top: 20rpx;">
					<up-cell-group :border="false">
						<up-cell title="报价单号">
							<template #value>
								<view class="cell-text">{{ detail_record.code }} </view>
							</template>
						</up-cell>
						<up-cell title="客户">
							<template #value>
								<view class="cell-text">{{ detail_record.client_name }} </view>
							</template>
						</up-cell>
						<up-cell title="交货日期">
							<template #value>
								<view class="cell-text">{{ detail_record.delivery_date }}</view>
							</template>
						</up-cell>
						<up-cell title="备注">
							<template #value>
								<view class="cell-text" style="width: 70%;">{{ detail_record.desc }}</view>
							</template>
						</up-cell>
					</up-cell-group>
				</view>
			</view>
			<view class="b-con">
				<up-cell-group :border="false">
					<up-cell :isLink="true" :border="false" :title="`产品：总数量（${car_list.length}）`" @click="car_popupShow = true">
						<template #value>
							<view class="cell-text">点击查看 </view>
						</template>
					</up-cell>
				</up-cell-group>
			</view>
			<custom-popup :popupShow="car_popupShow" mode="bottom" :title="'产品'" @close="car_popupShow = false" height="70vh">
				<z-paging v-if="car_popupShow" ref="paging_car" :refresher-enabled="false" :loading-more-enabled="false" :fixed="false" v-model="car_list"
					@query="queryList_car">
					<uni-card v-for="(item, index) in car_list" :key="index" :title="item.name" :sub-title="item.code"
						margin="5px" spacing="0">
						<view>规格：{{ item.specification }}</view>
						<view class="con" style="align-items: normal;">
							<view class="ctent" style="flex: none;">仓库【库存】：</view>
							<view class="ctent">{{ item.inventory_info }}</view>
						</view>
						<view class="con">
							<view class="ctent">成本价：{{ item.cost }}</view>
							<view class="ctent">销售单价：{{ item.main_price }}</view>
						</view>
						<view class="con">
							<view class="ctent">销售提成：{{ item.royalties }}%</view>
							<view class="ctent">销售单位：{{ item.market_unit }}</view>
						</view>
						<view class="con">
							<view class="ctent">数量：{{ item.num }}</view>
							<view class="ctent">总价：{{ item.gross_price }}</view>
						</view>
						<view class="con">
							<view class="ctent">优惠率(%)：{{ item.discount }}%</view>
							<view class="ctent">最终价：{{ item.total_price }}</view>
						</view>
					</uni-card>
				</z-paging>
			</custom-popup>
		</view>
	</view>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import oQuotationApi from '../../../api/order/o_quotation'

const detail_record = ref({})
const title = '报价单详情';
onLoad(option => {
	get_detail(option.id);
})
const car_popupShow = ref(false);
const car_list = ref([]);
function get_detail(id) {
	oQuotationApi.offer_order_detail(id).then(res => {
		detail_record.value = res
		car_list.value = res.offer_order_products.map(v => {
			const total = parseFloat(v.main_price) * v.num
			return {
				id: v.product.id,
				code: v.product.code,
				name: v.product.name,
				specification: v.product.specification,
				warehouse_name: v.product.warehouse_name,
				inventory: v.product.inventory,
				unit_main: v.product.unit_main,
				unit_assist_one_ratio: v.product.unit_assist_one_ratio,
				unit_assist_two_ratio: v.product.unit_assist_two_ratio,
				unit_assist_one: v.product.unit_assist_one,
				unit_assist_two: v.product.unit_assist_two,
				unit_main_price: v.product.unit_main_price,
				unit_assist_one_price: v.product.unit_assist_one_price,
				unit_assist_two_price: v.product.unit_assist_two_price,
				num: v.num,
				discount: parseFloat(v.discount),
				total_price: v.total_price,
				gross_price: parseFloat(total.toFixed(2)),
				market_unit: v.market_unit,
				cost: v.cost,
				royalties: v.royalties,
				main_price: v.main_price,
				all_cost: v.product.all_cost,
				inventory_info: v.product.stock_info.map(v => (`${v.warehouse_name}【${v.unit_info}】`)).join('、'),
			}
		})
	})
};

const paging_car = ref(null);
function queryList_car() {
	paging_car.value.complete(car_list.value);
};

</script>

<style lang="scss"></style>